import {
  AppItem,
  CancelParams,
  CompoItem,
  CreateParam,
  FinishParams,
  ShiftTableItem,
  ShiftTableParams,
  StatusItem,
} from './model/eventMgtTenantModel';
import { workOrderHttp } from '/@/utils/http/axios';

enum Api {
  CANCEL = '/v1/creator/drawback',
  REJECT = '/v1/creator/reject',
  FINISH = '/v1/creator/close',
  TABLE = '/v1/creator/page',
  STATUS = '/v1/creator/status',
  CREATE = '/v1/creator/create',
  APP = '/v1/creator/appList',
  COMPO = '/v1/creator/componentList',
}

export const cancelShift = async (params: CancelParams) => {
  const res = await workOrderHttp.get<string>({
    url: Api.CANCEL,
    params,
  });
  return res;
};

export const rejectShift = async (params: CancelParams) => {
  const res = await workOrderHttp.get<string>({
    url: Api.REJECT,
    params,
  });
  return res;
};

export const finishShift = async (params: FinishParams) => {
  const res = await workOrderHttp.get<string>({
    url: Api.FINISH,
    params,
  });
  return res;
};

export const getShiftTable = async (params: ShiftTableParams) => {
  const res = await workOrderHttp.post<ShiftTableItem>({
    url: Api.TABLE,
    params,
  });
  return res;
};

export const getStatus = async () => {
  const res = await workOrderHttp.get<StatusItem[]>({
    url: Api.STATUS,
  });
  res.map((item) => {
    return {
      label: item.description,
      value: item.statusCode,
    };
  });
  return res;
};

export const createShift = async (params: CreateParam) => {
  const res = await workOrderHttp.post<string>({
    url: Api.CREATE,
    params,
  });

  return res;
};

export const getAppList = async () => {
  const res = await workOrderHttp.get<AppItem[]>({
    url: Api.APP,
  });
  res.map((item) => {
    return { label: item.appName, value: item.appId };
  });
  return res;
};

export const getCompoList = async (params) => {
  const res = await workOrderHttp.get<CompoItem[]>({
    url: Api.COMPO,
    params,
  });
  res.map((item) => {
    return { label: item.name, value: item.id };
  });
  return res;
};
